//
//  SketchParse.m
//  SketchParse
//
//  Created by gao on 2017/10/11.
//  Copyright © 2017年 gao. All rights reserved.
//
#import "ARCMacro.h"
#import "SketchParse.h"
#import "OBShapedButton.h"

@implementation SketchParse

#pragma mark - 创建 UIImage
+(id)createUIImage:(NSString *)fileName
{
    NSString *path = [[NSBundle mainBundle]pathForResource:fileName ofType:@""];
    
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    
    return image;
}

#pragma mark - 创建 UIImageView
+(id)createUIImageView:(NSString *)fileName frame:(CGRect)rect
{
    UIImage *image = [self createUIImage:fileName];
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:rect];
    
    imageView.image = image;
    
    [imageView setContentMode:UIViewContentModeScaleAspectFit];
    
    return SAFE_ARC_AUTORELEASE(imageView);
    
}

//////////////////////////////////////////////////////////////
#pragma mark - 创建 UIImageView
//////////////////////////////////////////////////////////////
+(id)createUIImageView:(NSString *)fileName centerPoint:(CGPoint)centerPoint size:(CGSize)size tag:(int)tag
{
    UIImage *image = [self createUIImage:fileName];
    
    UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
    
    CGRect rect = imageView.frame;
    
    rect.size = size;
    
    imageView.frame = rect;
    
    imageView.center = centerPoint;
    
    imageView.tag = tag;
    
    return SAFE_ARC_AUTORELEASE(imageView);
}




//////////////////////////////////////////////////////////////
#pragma mark - 创建 UIButton
//////////////////////////////////////////////////////////////
+(id)createUIButton:(NSString *)fileName centerPoint:(CGPoint)point size:(CGSize)size selected:(NSString *)selecded disabled:(NSString *)disabled Highlighted:(NSString *)Highlighted target:(id)target event:(SEL)event tag:(int)tag
{
    UIImage *image = [self createUIImage:fileName];
    
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height)];
    
    [button setImage:image forState:UIControlStateNormal];
    
    button.center = point;
    
    [button addTarget:target action:event forControlEvents:UIControlEventTouchUpInside];
    
    if (Highlighted) {
        [button setImage:[self createUIImage:Highlighted] forState:UIControlStateHighlighted];
    }
    
    if (selecded) {
        [button setImage:[self createUIImage:selecded] forState:UIControlStateSelected];
    }
    
    if (disabled) {
        [button setImage:[self createUIImage:disabled] forState:UIControlStateDisabled];
    }
    button.tag = tag;
    return SAFE_ARC_AUTORELEASE(button);
}
+(id)createOBShapeButton:(NSString *)fileName centerPoint:(CGPoint)point size:(CGSize)size selected:(NSString *)selecded disabled:(NSString *)disabled Highlighted:(NSString *)Highlighted target:(id)target event:(SEL)event tag:(int)tag{
    UIImage *image = [self createUIImage:fileName];
    
    OBShapedButton *button = [[OBShapedButton alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height)];
    
    [button setImage:image forState:UIControlStateNormal];
    
    button.center = point;
    
    [button addTarget:target action:event forControlEvents:UIControlEventTouchUpInside];
    
    if (Highlighted) {
        [button setImage:[self createUIImage:Highlighted] forState:UIControlStateHighlighted];
    }
    
    if (selecded) {
        [button setImage:[self createUIImage:selecded] forState:UIControlStateSelected];
    }
    
    if (disabled) {
        [button setImage:[self createUIImage:disabled] forState:UIControlStateDisabled];
    }
    button.tag = tag;
    return SAFE_ARC_AUTORELEASE(button);

}

#pragma mark - 创建背景透明文字按钮
+(id)createUIButton:(NSString *)text centerPoint:(CGPoint)centerPoint size:(CGSize)size font:(UIFont *)font textColor:(UIColor *)textColor highlightedTextColor:(UIColor *)highlightedTextColor selectedTextColor:(UIColor *)selectedTextColor target:(id)target event:(SEL)event tag:(int)tag;
{
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, size.width, size.height)];
    
    btn.center = centerPoint;
    
    [btn setTitleColor:textColor forState:UIControlStateNormal];
    
    [btn setTitle:text forState:UIControlStateNormal];
    
    if (highlightedTextColor) {
        [btn setTitleColor:highlightedTextColor forState:UIControlStateHighlighted];
    }
    
    if (selectedTextColor) {
        [btn setTitleColor:selectedTextColor forState:UIControlStateSelected];
    }
    
    [btn addTarget:target action:event forControlEvents:UIControlEventTouchUpInside];
    
    btn.tag = tag;
    
    btn.titleLabel.font = font;
    
    return SAFE_ARC_AUTORELEASE(btn);
}

#pragma mark - 创建 UILabel
+(id)createUILabel:(NSString *)text frame:(CGRect)rect font:(UIFont *)font textColor:(UIColor*)textColor backgroundColor:(UIColor *)backgroundColor textAlignment:(NSTextAlignment)textAlignment tag:(int)tag
{
    UILabel *label = [[UILabel alloc]initWithFrame:rect];
    
    if (backgroundColor) {
        label.backgroundColor = backgroundColor;
    }
    else{
        label.backgroundColor = [UIColor clearColor];
    }
    label.textColor = textColor;
    
    label.font = font;
    
    label.text = text;
    
    label.textAlignment = textAlignment;
    
    label.tag = tag;
    
    return SAFE_ARC_AUTORELEASE(label);
}


#pragma mark - 创建 UITextField
+(id)createUITextField:(NSString *)placeholder x:(float)x width:(float)width height:(float)height centerPointY:(float)centerPointY font:(UIFont*)font textColor:(UIColor *)textColor backgroundColor:(UIColor *)backgroundColor borderStyle:(UITextBorderStyle )borderStyle delegate:(id)delegate tag:(int)tag
{
    UITextField *field = [[UITextField alloc]initWithFrame:CGRectMake(x,0,width,height)];
    
    CGPoint centerPoint = field.center;
    
    centerPoint.y = centerPointY;
    
    field.center = centerPoint;
    
    if (backgroundColor) {
        field.backgroundColor = backgroundColor;
    }
    else
    {
        field.backgroundColor = [UIColor clearColor];
    }
    
    
    field.textColor = textColor;
    
    field.font = font;
    
    field.tag = tag;
    
    field.placeholder = placeholder;
    
    field.borderStyle = borderStyle;
    
    field.delegate = delegate;
    
    return SAFE_ARC_AUTORELEASE(field);
    
}

//#pragma mark - 创建 有placeholder 且可以多行输入的UITextField
//+(id)createMultilineUITextField:(NSString *)placeholder frame:(CGRect)rect font:(UIFont *)font textColor:(UIColor *)textColor backgroundColor:(UIColor *)backgroundColor delegate:(id)delegate tag:(int)tag
//{
//    CPTextViewPlaceholder *textView = [[CPTextViewPlaceholder alloc]initWithFrame:rect];
//
//
//
//    textView.textColor = textColor;
//
//    textView.font = font;
//
//    if (backgroundColor) {
//
//        textView.backgroundColor = backgroundColor;
//    }
//    else
//    {
//        textView.backgroundColor = [UIColor clearColor];
//    }
//
//
//    textView.delegate = delegate;
//
//    textView.tag = tag;
//
//    textView.placeholder = placeholder;
//
//
//    return SAFE_ARC_AUTORELEASE(textView);
//}


#pragma mark - 创建 UIView
+(id)createUIViewWithFrame:(CGRect)rect backgroundColor:(UIColor *)backgroundColor cornerRadius:(int)cornerRadius borderColor:(UIColor*)borderColor borderWidth:(int)borderWidth tag:(int)tag
{
    UIView *view = [[UIView alloc]initWithFrame:rect];
    
    view.backgroundColor = backgroundColor;
    
    if (cornerRadius != 0) {
        view.layer.masksToBounds = YES;
        
        view.layer.cornerRadius = cornerRadius;
        
        if (borderColor) {
            view.layer.borderColor = borderColor.CGColor;
            view.layer.borderWidth = borderWidth;
        }
    }
    
    view.tag = tag;
    
    return SAFE_ARC_AUTORELEASE(view);
}

@end
